/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sk.itat.wicket;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

/**
 *
 * @author opteron1441
 */
public final class WelcomePage extends BasePage {

    public WelcomePage() {
        super();

        add(new HeaderPanel("mainNavigation", "Welcome"));
    }

    public WelcomePage(final Uzivatel person) {
        super();

        add(new HeaderPanel("mainNavigation", "Vitajte " + person.getFirstName() + " !"));
        add(new Label("firstName",person.getFirstName()));
        add(new Label("lastName",person.getLastName()));
        add(new Label("adress", person.getAdresa()));
        add(new Label("telefon", String.valueOf(person.getTelCislo())));
        add(new Label("mail", person.getEmail()));
        add(new Label("krajina", person.getKrajina()));
        add(new Label("firma", person.getSpolocnost()));



        add(new ListView<RoomRegistration>("list", person.getZoznamRezervacii()) {

            @Override
            protected void populateItem(ListItem<RoomRegistration> item) {
                final RoomRegistration romReg = item.getModelObject();
                item.add(new Label("hotel", romReg.getHotel()));
                item.add(new Label("velkostIzby",String.valueOf(romReg.getVelkostIzby())));
                item.add(new Label("dlzkaRezervacie", String.valueOf(romReg.getDlzkaRezervacie())));
                item.add(new Label("datum",romReg.getDatum()));
                item.add(new Link("deleteTermin") {

                    @Override
                    public void onClick() {
                       person.getZoznamRezervacii().remove(romReg);
                       setResponsePage(new WelcomePage(person));
                    }
                });

            }
        });

        add(new ListView<PresentRoomReg>("list_pred", person.getZoznamPrezentacii()) {

            @Override
            protected void populateItem(ListItem<PresentRoomReg> item) {
               final PresentRoomReg presRoom = (PresentRoomReg)item.getModelObject();
               item.add(new Label("hotel_pred", presRoom.getHotel()));
               item.add(new Label("nazov", presRoom.getNazovPrednasky()));
               item.add(new Label("dlzka", String.valueOf(presRoom.getDlzkaPrednasky())));
               item.add(new Label("datum_pred", presRoom.getDatum()));
               if(presRoom.isVerejnaPrednaska()){
                   item.add(new Label("verejna", "ano"));
               } else {
                   item.add(new Label("verejna", "nie"));
               }
               item.add(new Link("deleteTermin_pred") {

                    @Override
                    public void onClick() {
                       person.getZoznamPrezentacii().remove(presRoom);
                       setResponsePage(new WelcomePage(person));
                    }
                });
            }
        });


        add(new Link("addRoom") {

            @Override
            public void onClick() {
                setResponsePage(new ReservationRoomPage(person));
            }
        });
        add(new Link("addPresentation") {

            @Override
            public void onClick() {
                setResponsePage(new ReservationPresenRoomPage(person));
            }
        });
        add(new Button("logout") {

            @Override
            public void onSubmit() {
                setResponsePage(LoginPage.class);
            }
        });


        //TODO:  process page parameters
    }
}
